package com.alphacsp.theedge2012.ui.activities;

import android.app.SearchManager;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;
import android.widget.TextView;
import com.alphacsp.theedge2012.R;

/**
 * Created by IntelliJ IDEA.
 * User: Gilad
 * Date: 31/10/10
 * Time: 23:26
 */
public class SearchActivity extends TabActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search_activity);

        Intent intent = getIntent();
        String query = intent.getStringExtra(SearchManager.QUERY);

        final TabHost host = getTabHost();

        Intent speakersIntent = new Intent(SearchActivity.this, SpeakersActivity.class);
        speakersIntent.putExtra(SearchManager.QUERY, query);
        host.addTab(host.newTabSpec("Speakers").setIndicator(buildIndicator("Speakers")).setContent(speakersIntent));

        Intent sessionsIntent = new Intent(SearchActivity.this, SessionsActivity.class);
        sessionsIntent.putExtra(SearchManager.QUERY, query);
        host.addTab(host.newTabSpec("Sessions").setIndicator(buildIndicator("Sessions")).setContent(sessionsIntent));
    }

    public void onHomeClick(View view) {
        final Intent intent = new Intent(getApplicationContext(), HomeActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }

    @SuppressWarnings({"UnusedDeclaration"})
    public void onSearchClick(View v) {
        onSearchRequested();
    }

    private View buildIndicator(String text) {
        final TextView indicator = (TextView) getLayoutInflater().inflate(R.layout.tab_indicator, getTabWidget(), false);
        indicator.setText(text);
        return indicator;
    }

}
